<template>
	<view>
		<view class="con">
			<view class="con__box">
				<image src="/static/points/boxbg.png" class="con__box__bg" mode=""></image>

				<view class="con__box__c">
					<view class="">
						<view class="con__box__t">
							我的积分
						</view>
						<view class="con__box__num">
							{{userInfo.score}}
						</view>
					</view>
					<image src="/static/task/hb.png" class="con__box__hb" mode=""></image>
				</view>
			</view>
			<view class="con__form">
				<view class="con__form__title">
					积分报价
					<text style="font-size: 20rpx;color: #E3432D;margin-left: 4rpx;"
						v-if="info.id">(请先取消当前售价才能修改报价)</text>
				</view>
				<view class="con__form__item" style="margin-bottom: 20rpx;">
					<!-- <input type="text" class="con__form__item__inp" v-model="val" /> -->
					<u-input placeholder="积分报价" border="none" color="#E3432D" v-model="info.price" :readonly="info.id"
						type="number">
						<template slot="prefix">
							<view class="" style="color: #E3432D;font-size: 22rpx;">
								￥
							</view>
						</template>
						<template slot="suffix">
							<view class="">
								=10积分
							</view>
						</template>
					</u-input>
				</view>
				<view class="con__form__title">
					出售积分
				</view>
				<view class="con__form__item">
					<input type="number" class="con__form__item__inp" v-model="num" />
				</view>
				<view class="con__form__text">
					我的积分：{{userInfo.score}} <text style="color: #E3432D;margin-left: 30rpx;"
						@click="num=userInfo.score">全部出售</text>
				</view>
				<u-button
					:customStyle="{width:'638rpx',height:'95rpx',padding:0,fontSie:'30rpx',margin:'0 0 0 6rpx',borderRadius:'30rpx'}"
					color="#E3432D" text="出售" @click="cS"></u-button>
			</view>
			<!-- 			<view class="con__form">
				<view class="con__form__title">
					温馨提示
				</view>
				<view class="con__form__text" style="line-height: 36rpx;color: #1E1E1E;margin-bottom: 0;">
					1、积分每日根据涨幅情况定价。</br>
					2、积分售卖10积分起售。
				</view>
			</view> -->
			<view class="con1__form" v-if="info.id">
				<view class="con1__form__title">
					我的当前出售
				</view>
				<view class="con1__item" style="padding-bottom: 0;">
					<image src="/static/points/icon.png" class="con1__item__icon" mode=""></image>
					<view class="" style="flex: 1;">
						<!-- 		<view class="con1__item__name">
							时光匆匆
						</view> -->
						<view class="con1__item__time">
							10积分=
							<text style="color: #E3432D;font-size: 36rpx;">
								<text style="font-size: 24rpx;">￥</text>{{info.price}}
							</text>
						</view>
					</view>
					<view class="">
						<view class="con1__item__jf" style="margin-bottom: 10rpx;">
							库存:{{info.num}} 积分
						</view>
						<u-button :customStyle="{width:'131rpx',height:'52rpx',padding:0,fontSie:'24rpx',margin:'0',}"
							shape='circle' color="#E3432D" text="取消出售" @click="delS"></u-button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		createscore,
		myscore,
		delscore
	} from "@/request/api/sell.js"
	import {
		userInfo
	} from "@/request/api/my.js"
	export default {
		data() {
			return {

				userInfo: {
					score: 0
				},
				num: 0,
				info: {
					num: 0,
					price: 0,
				}
			};
		},
		onLoad() {
			userInfo().then(res => {
				this.userInfo = res.data;
			})
			myscore().then(res => {
				if (res.data) {
					this.info = res.data;
					this.num = 0;
				} else {
					this.info = {
						num: 0,
						price: 0,
					}
					this.num = 0;
				}

			})
		},
		methods: {
			cS() {
				if (this.price == 0) return;
				if (this.num == 0) return;
				if (this.num > this.userInfo.score) {
					uni.$u.toast('你没有这么多积分');
					return
				}
				createscore({
					num: this.num,
					price: this.info.price
				}).then(res1 => {
					myscore().then(res => {
						this.info = res.data;
						this.num = 0;
					})
				})
			},
			delS() {
				delscore({
					id: this.info.id
				}).then(res => {
					userInfo().then(res1 => {
						this.userInfo = res1.data;
					})
					this.info = {
						num: 0,
						price: 0
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.con {
		padding: 30rpx;

		&__box {
			width: 690rpx;
			height: 182rpx;
			position: relative;
			margin-bottom: 27rpx;

			&__bg {
				width: 690rpx;
				height: 182rpx;
				position: absolute;
				top: 0;
				left: 0;
			}

			&__c {
				width: 690rpx;
				height: 182rpx;
				position: absolute;
				top: 0;
				left: 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			&__hb {
				width: 142rpx;
				height: 160rpx;
				margin-right: 48rpx;
			}

			&__t {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #000000;
				line-height: 24rpx;
				margin: 30rpx 0 16rpx 37rpx;
			}

			&__num {
				font-family: DINNextLTPro;
				font-weight: bold;
				font-size: 68rpx;
				color: #000000;
				margin-left: 37rpx;
			}
		}

		&__form {
			background: #FEFFFF;
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			padding: 38rpx 20rpx 38rpx;
			margin-top: 20rpx;

			&__title {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 27rpx;
				color: #1E1E1E;
				line-height: 27rpx;
				margin-left: 7rpx;
			}

			&__item {
				height: 107rpx;
				padding-left: 8rpx;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #F3F3F3;

				&__label {
					width: 2rpx;
					height: 51rpx;
					background: #F9480B;
					margin-right: 8rpx;
				}

				&__inp {
					font-family: DINNextLTPro;
					font-weight: 500;
					font-size: 72rpx;
					color: #000000;
					display: flex;
					align-items: center;
					margin-top: 10rpx;
				}

			}

			&__text {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #000000;
				line-height: 24rpx;
				margin: 28rpx 0 41rpx 3rpx;
			}

		}

	}

	.con1 {
		&__form {
			background: #FEFFFF;
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			padding: 38rpx 20rpx 38rpx;
			margin-top: 20rpx;

			&__title {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 27rpx;
				color: #1E1E1E;
				line-height: 27rpx;
				margin-left: 7rpx;
			}
		}

		&__item {
			display: flex;
			align-items: center;
			padding: 43rpx 22rpx 28rpx 27rpx;
			background: #FFFFFF;
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			margin-bottom: 27rpx;

			&__icon {
				width: 90rpx;
				height: 90rpx;
				margin-right: 18rpx;
			}

			&__name {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #1E1E1E;
				line-height: 28rpx;
				margin-bottom: 23rpx;
			}

			&__time {
				font-family: DINNextLTPro;
				font-weight: 500;
				font-size: 25rpx;
				color: #929292;
				line-height: 25rpx;
			}

			&__jf {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #E3432D;
				line-height: 24rpx;
				display: flex;
			}

			&__num {
				font-family: DINNextLTPro;
				font-weight: 500;
				font-size: 31rpx;
				color: #E3432D;
				line-height: 31rpx;
			}
		}
	}
</style>